package com.kk.xhr.admin.util;

import com.kk.xhr.model.dto.SalaryDTO;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 邮箱内容HTML绘制工具
 *
 * @author kkmystery
 * @version 1.0 2021/3/30
 * @since 1.0.0
 */
public class MailUtil {

    /**
     * 生成表格html
     *
     * @param salary 工资账单
     * @return html文本
     */
    public static String generateSalaryTable(SalaryDTO salary, String name) {
        LocalDate mouth = LocalDate.now().minusMonths(1L);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String template = "<!DOCTYPE html>\n" +
            "<html lang=\"en\">\n" +
            "<head>\n" +
            "  <meta charset=\"UTF-8\">\n" +
            "  <title>叮咚！" + name + "，您的" + mouth.getMonth() + "月薪资账单出炉啦！</title>\n" +
            "</head>\n" +
            "<body>\n" +
            "<div style=\"border-style: inset;border-width: medium;width: 500px\">\n" +
            "  <div style=\"margin: 5px\">\n" +
            "    <span style=\"text-align: left;font-size: 25px;padding: 10px\">工资账单</span>\n" +
            "    <span style=\"float: right;font-weight: bold\">日期: " + mouth.format(dateTimeFormatter) + "</span>\n" +
            "  </div>\n" +
            "\n" +
            "  <table border=\"2px\" width=\"100%\">\n" +
            "    <tr>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">基本工资: </span><span style=\"margin-left: 5px\">" + salary.getBasicSalary() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">奖金: </span><span\n" +
            "        style=\"margin-left: 5px\">" + salary.getBonus() + "(元)</span></td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">工时: </span><span\n" +
            "        style=\"margin-left: 5px\">" + salary.getWorkTime() + "(小时)</span></td>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">缺勤次数: </span><span style=\"margin-left: 5px\">" + salary.getAbsenceDay() + "(次数)</span>\n" +
            "      </td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">午餐补助: </span><span style=\"margin-left: 5px\">" + salary.getLunchSalary() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">交通补助: </span><span style=\"margin-left: 5px\">" + salary.getTrafficSalary() + "(元)</span>\n" +
            "      </td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">养老金基数: </span><span style=\"margin-left: 5px\">" + salary.getPensionBase() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">养老金比率: </span><span style=\"margin-left: 5px\">" + salary.getPensionPercentage() + "(%)</span>\n" +
            "      </td>\n" +
            "      <td style=\"font-weight: bold;font-size: 20px\">养老金</td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">医疗基数: </span><span style=\"margin-left: 5px\">" + salary.getMedicalBase() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">医疗保险比率: </span><span style=\"margin-left: 5px\">" + salary.getMedicalPercentage() + "(%)</span>\n" +
            "      </td>\n" +
            "      <td style=\"font-weight: bold;font-size: 20px\">医疗</td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">公积金基数: </span><span style=\"margin-left: 5px\">" + salary.getAccumulationFundBase() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"40%\"><span style=\"font-weight: bold;font-size: 20px\">公积金比率: </span><span style=\"margin-left: 5px\">" + salary.getAccumulationFundPercentage() + "(%)</span>\n" +
            "      </td>\n" +
            "      <td style=\"font-weight: bold;font-size: 20px\">公积金</td>\n" +
            "    </tr>\n" +
            "    <tr>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">个人所得税: </span><span style=\"margin-left: 5px\">" + salary.getIndividualTax() + "(元)</span>\n" +
            "      </td>\n" +
            "      <td width=\"50%\"><span style=\"font-weight: bold;font-size: 20px\">最终工资: </span><span style=\"margin-left: 5px\">" + salary.getFinalSalary() + "(元)</span>\n" +
            "      </td>\n" +
            "    </tr>\n" +
            "  </table>\n" +
            "</div>\n" +
            "</body>\n" +
            "</html>\n";

        return template;
    }
}
